module.exports = function ($scope, $resource, $modalInstance, FileUploader, toaster, travel) {
    
    //出境游信息为null时,表示添加出境游,不为null时表示修改
    if(travel){
        $resource('/api/as/goc/outboundtravel/getTravelInfo', {}, {}).save({'group_code': travel.group_code}, function(res){
            if (res.errcode === 0) {
                $scope.group = res.data;
            } else {
                toaster.error({title: '', body: '查询失败'});
            }
        });
    } else {
        $scope.group =  {'contain_travel': '1', 'contain_room': '1'};
    }
    
    //校验出境游信息
    function check(info){
        if(!info.group_name){
            toaster.warning({'title': '', 'body': '请填写游团名称'});
            return false;
        }
        if(!info.group_theme){
            toaster.warning({'title': '', 'body': '请填写游团主题'});
            return false;
        }
        if(!info.from_place){
            toaster.warning({'title': '', 'body': '请填写出发城市'});
            return false;
        }
        if(!info.arrive_place){
            toaster.warning({'title': '', 'body': '请填写游玩地区'});
            return false;
        }
        if(!info.period && info.period > 0){
            toaster.warning({'title': '', 'body': '出游天数不正确'});
            return false;
        }
        return true;
    }

    //保存
    $scope.ok = function(){
        if(!check($scope.group)) return;
        $resource('/api/ac/goc/outboundTravelService/addOutboundTravel', {}, {}).save($scope.group, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '添加成功'});
                $modalInstance.close();
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

    $scope.uploader = new FileUploader({
        url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb'
    });
	
    //上传图片成
    $scope.uploader.onSuccessItem = function (fileItem, response, status, headers) {
        $scope.group.img_url = response.savename;
    }

};